package com.ts.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
    @Autowired
    ApiInterceptor apiInterceptor;
    @Autowired
    OpenApiInterceptor openApiInterceptor;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/files/**").addResourceLocations("file:" + TsConfig.getUploadPath());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 自定义拦截器，添加拦截路径和排除拦截路径
        registry.addInterceptor(apiInterceptor).addPathPatterns("/**");
        // 自定义拦截器，添加拦截路径和排除拦截路径
        registry.addInterceptor(openApiInterceptor).addPathPatterns("/animal/open/api/**");
    }

}
